---
title: SAP AI Core
description: SAP AI Core Provider for the AI SDK
---

# SAP AI Core

## Important Note

> **Third-Party Provider**: This SAP AI Core provider (`@mymediset/sap-ai-provider`) is developed and maintained by Mymediset, not by SAP SE. While it integrates with official SAP AI Core services, it is not an official SAP product. For official SAP AI solutions, please refer to the [SAP AI Core Documentation](https://help.sap.com/docs/ai-core).

[SAP AI Core](https://help.sap.com/docs/ai-core) is SAP's enterprise-grade AI platform that provides access to leading AI models from OpenAI, Anthropic, Google, Amazon, and more through a unified, secure, and scalable infrastructure. The SAP AI Core provider for the AI SDK enables seamless integration with enterprise AI capabilities while offering unique advantages:

- **Multi-Model Access**: Support for 40+ models including GPT-4, Claude, Gemini, and Amazon Nova
- **OAuth Integration**: Automatic authentication handling with SAP BTP
- **Cost Management**: Enterprise billing and usage tracking through SAP BTP
- **High Availability**: Enterprise-grade infrastructure with SLA guarantees
- **Hybrid Deployment**: Support for both cloud and on-premise deployments
- **Tool Calling**: Full function calling capabilities for compatible models
- **Multi-modal Support**: Text and image inputs for compatible models

Learn more about SAP AI Core's capabilities in the [SAP AI Core Documentation](https://help.sap.com/docs/ai-core).

## Setup

The SAP AI Core provider is available in the `@mymediset/sap-ai-provider` module. You can install it with:

<Tabs items={['pnpm', 'npm', 'yarn', 'bun']}>
  <Tab>
    <Snippet text="pnpm add @mymediset/sap-ai-provider" dark />
  </Tab>
  <Tab>
    <Snippet text="npm install @mymediset/sap-ai-provider" dark />
  </Tab>
  <Tab>
    <Snippet text="yarn add @mymediset/sap-ai-provider" dark />
  </Tab>
  <Tab>
    <Snippet text="bun add @mymediset/sap-ai-provider" dark />
  </Tab>
</Tabs>

## Provider Instance

To create an SAP AI Core provider instance, use the `createSAPAIProvider` function:

```typescript
import { createSAPAIProvider } from '@mymediset/sap-ai-provider';

const sapai = await createSAPAIProvider({
  serviceKey: 'YOUR_SAP_AI_CORE_SERVICE_KEY',
});
```

You can obtain your SAP AI Core service key from your SAP BTP Cockpit by creating a service key for your AI Core instance.

## Language Models

You can create SAP AI Core models using the provider instance and model name:

```typescript
// OpenAI models
const gpt4Model = sapai('gpt-4o');

// Anthropic models
const claudeModel = sapai('anthropic--claude-3-sonnet');

// Google models
const geminiModel = sapai('gemini-1.5-pro');

// Amazon models
const novaModel = sapai('amazon--nova-pro');
```

## Supported Models

The provider supports a wide range of models available in your SAP AI Core deployment:

### OpenAI Models

- `gpt-4`, `gpt-4o`, `gpt-4o-mini`
- `o1`

### Anthropic Models

- `anthropic--claude-3-haiku`, `anthropic--claude-3-sonnet`, `anthropic--claude-3-opus`
- `anthropic--claude-3.5-sonnet`

### Google Models

- `gemini-1.5-pro`, `gemini-1.5-flash`
- `gemini-2.0-pro`, `gemini-2.0-flash`

### Amazon Models

- `amazon--nova-premier`, `amazon--nova-pro`, `amazon--nova-lite`, `amazon--nova-micro`

### Other Models

- `mistralai--mistral-large-instruct`
- `meta--llama3-70b-instruct`, `meta--llama3.1-70b-instruct`

Note: Model availability may vary based on your SAP AI Core subscription and region. Some models may require additional configuration or permissions.

## Examples

Here are examples of using SAP AI Core with the AI SDK:

### generateText

```typescript
import { createSAPAIProvider } from '@mymediset/sap-ai-provider';
import { generateText } from 'ai';

const sapai = await createSAPAIProvider({
  serviceKey: process.env.SAP_AI_SERVICE_KEY,
});

const { text } = await generateText({
  model: sapai('gpt-4o'),
  prompt: 'What are the benefits of enterprise AI platforms?',
});

console.log(text);
```

### streamText

```typescript
import { createSAPAIProvider } from '@mymediset/sap-ai-provider';
import { streamText } from 'ai';

const sapai = await createSAPAIProvider({
  serviceKey: process.env.SAP_AI_SERVICE_KEY,
});

const result = streamText({
  model: sapai('anthropic--claude-3-sonnet'),
  prompt: 'Write a short story about AI.',
});

for await (const textPart of result.textStream) {
  console.log(textPart);
}
```

### Tool Calling

```typescript
import { createSAPAIProvider } from '@mymediset/sap-ai-provider';
import { generateText, tool } from 'ai';
import { z } from 'zod';

const sapai = await createSAPAIProvider({
  serviceKey: process.env.SAP_AI_SERVICE_KEY,
});

const result = await generateText({
  model: sapai('gpt-4o'),
  prompt: 'What is the current status of our inventory system?',
  tools: {
    checkInventory: tool({
      description: 'Check current inventory levels',
      inputSchema: z.object({
        item: z.string().describe('Item to check'),
        location: z.string().describe('Warehouse location'),
      }),
      execute: async ({ item, location }) => {
        // Your inventory system integration
        return { item, location, quantity: 150, status: 'In Stock' };
      },
    }),
  },
});

console.log(result.text);
```

### Multi-modal Input

```typescript
import { createSAPAIProvider } from '@mymediset/sap-ai-provider';
import { generateText } from 'ai';

const sapai = await createSAPAIProvider({
  serviceKey: process.env.SAP_AI_SERVICE_KEY,
});

const result = await generateText({
  model: sapai('gpt-4o'),
  messages: [
    {
      role: 'user',
      content: [
        { type: 'text', text: 'Analyze this business process diagram.' },
        {
          type: 'image',
          image: '...',
        },
      ],
    },
  ],
});

console.log(result.text);
```

## Configuration

### Provider Settings

```typescript
interface SAPAIProviderSettings {
  serviceKey?: string; // SAP AI Core service key JSON
  token?: string; // Direct access token (alternative to serviceKey)
  baseURL?: string; // Custom base URL for API calls
}
```

### Model Settings

```typescript
interface SAPAIModelSettings {
  modelParams?: {
    maxTokens?: number; // Maximum tokens to generate
    temperature?: number; // Sampling temperature (0-2)
    topP?: number; // Nucleus sampling parameter
    frequencyPenalty?: number; // Frequency penalty (-2 to 2)
    presencePenalty?: number; // Presence penalty (-2 to 2)
  };
  safePrompt?: boolean; // Enable safe prompt filtering
  structuredOutputs?: boolean; // Enable structured outputs
}
```

## Environment Variables

### Required

Your SAP AI Core service key:

```bash
SAP_AI_SERVICE_KEY='{"serviceurls":{"AI_API_URL":"..."},"clientid":"...","clientsecret":"..."}'
```

### Optional

Direct access token (alternative to service key):

```bash
SAP_AI_TOKEN='your-access-token'
```

Custom base URL:

```bash
SAP_AI_BASE_URL='https://api.ai.prod.eu-central-1.aws.ml.hana.ondemand.com'
```

## Enterprise Features

SAP AI Core offers several enterprise-grade features:

- **Multi-Tenant Architecture**: Isolated environments for different business units
- **Cost Allocation**: Detailed usage tracking and cost center allocation
- **Custom Models**: Deploy and manage your own fine-tuned models
- **Hybrid Deployment**: Support for both cloud and on-premise installations
- **Integration Ready**: Native integration with SAP S/4HANA, SuccessFactors, and other SAP solutions

For more information about these features and advanced configuration options, visit the [SAP AI Core Documentation](https://help.sap.com/docs/ai-core).

## Additional Resources

- [SAP AI Provider Repository](https://github.com/BITASIA/sap-ai-provider)
- [SAP AI Core Documentation](https://help.sap.com/docs/ai-core)
- [SAP BTP Documentation](https://help.sap.com/docs/btp)
- [SAP Community](https://community.sap.com/t5/c-khhcw49343/SAP+AI+Core/pd-p/73555000100800003283)
- [SAP AI Core Service Guide](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide)
